var app = getApp();

var pageData = {
    data: {
      defaultSize: 'default',
      primarySize: 'default',
      warnSize: 'default',
      disabled: false,
      plain: false,
      loading: false,
      text_val:'',

   
      xuan_flag:'dis_flag',
      UserInfo:{
        user:'',
        user_number:0,
        password:0,
        Determine_pass:0,
        pass_protect:"",
      },
      user_mibao: "请选择"
    },
    onLoad: function (e) {

    },
    onShow: function () {

    },
    user(e){  //账号
    this.data.UserInfo.user = e.detail.value;
  },
  user_number(e) {  //账号
    this.data.UserInfo.user_number = e.detail.value;
  },
  password(e) {  //密码
    this.data.UserInfo.password = e.detail.value;
  },
  Determine_pass(e) {  //确认密码
    this.data.UserInfo.Determine_pass = e.detail.value;
  },
  val_text(e) {  //选着密码保护

    this.setData({
        user_mibao: e.currentTarget.dataset.value,
        xuan_flag: "dis_flag"
    });
    this.data.UserInfo.user_mibao = e.currentTarget.dataset.value;
  },
  pass_protect(e) {  //密保
    this.data.UserInfo.pass_protect = e.detail.value;
  },

    val_tex(){  //点击密码保护
      this.setData({
        xuan_flag: ""
      });
    },

  warn(e){ //提交 更新的地址
    this.setData({
      loading:true
    });

    if (this.data.UserInfo.user == "") {
                wx.showToast({
                  title: '请填写昵称',
                  image: '/images/jinggao.png',
                 duration: 1000
          });
      return false;
    };
    if (this.data.UserInfo.user_number == "") {

      wx.showToast({
        title: '请填写手机号码',
        image: '/images/jinggao.png',
        duration: 1000
      });
      return false;
    };
    var clform = /^1[3,4,5,7,8]\d{9}$/;
    if (!clform.test(this.data.UserInfo.user_number)) {
      wx.showToast({
        title: '手机号码格式不正确！',
        image: '/images/jinggao.png',
        duration: 1000
      });
      return false;
    };
    if (this.data.UserInfo.password == '') {

      wx.showToast({
        title: '请填写密码',
        image: '/images/jinggao.png',
        duration: 1000
      });
      return false;
    };
    if ( this.data.UserInfo.password.length < 6) {
      wx.showToast({
        title: '密码位数必须大于6位',
        image: '/images/jinggao.png',
        duration: 1000
      });
      return false;
    };

    if (this.data.UserInfo.Determine_pass == "") {
      wx.showToast({
        title: '请填写确认密码',
        image: '/images/jinggao.png',
        duration: 1000
      });
      return false;
    };
    if (this.data.UserInfo.password != this.data.UserInfo.Determine_pass) {
      wx.showToast({
        title: '两次密码不一致',
        image: '/images/jinggao.png',
        duration: 1000
      });
      return false;
    };
    if (this.data.UserInfo.user_mibao == "") {
      wx.showToast({
        title: '选择密码保护',
        image: '/images/jinggao.png',
        duration: 1000
      });
      return false;
    };
    if (this.data.UserInfo.pass_protect  == "") {
      wx.showToast({
        title: '请填写密码保护',
        image: '/images/jinggao.png',
        duration: 1000
      });
      return false;
    };
    var url = app.globalData.HOST + app.APILIST.register;
    var data = {
      "data": {
        "nickname": this.data.UserInfo.user,
        "phone": this.data.UserInfo.user_number,
        'password': this.data.UserInfo.password,
        "ask": this.data.UserInfo.user_mibao,
        'answer': this.data.UserInfo.pass_protect
      }
    };
    app.WxRequest(url,data, 1,
      (res) => {
        if (res.status_code == 200){
          wx.showToast({
            title: res.Massage,
            image: '/images/dui.png',
            duration: 1000
          });
          this.setData({
            loading: false
          });
        }
      }, (ref) => {
      });

  },


  model_address(e){  //获取 地址的值
    this.data.text_val = e.detail.value;
    // console.log(e.detail.value)
  }

};
Page(pageData);
